﻿namespace ExamV5.LineStudyExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class TaskTree : Page
    {
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private HttpCookie httpCookie_4 = null;
        private PublicFun publicFun_0 = new PublicFun();
        //protected TreeView TreeSubject;
        protected Label lblTreeType;

        private void method_0(string string_0, TreeNode treeNode_0, string string_1, string string_2)
        {
            //TreeNode child = new TreeNode {
            //    Value = string_1,
            //    Text = string_0,
            //    ToolTip = string_2,
            //    NavigateUrl = "TaskInfoList.aspx?SubjectID=" + string_1,
            //    Target = "mainBookFrame"
            //};
            //if (!(!(string_2 == "0") ? !(string_0 == "所有科目信息") : false))
            //{
            //    this.TreeSubject.Nodes.Add(child);
            //    treeNode_0.Expanded = true;
            //}
            //else
            //{
            //    treeNode_0.ChildNodes.Add(child);
            //    treeNode_0.Expanded = false;
            //}
            //string cmdText = "";
            //cmdText = "select * from SubjectInfo where UPID='" + string_1 + "' and (BrowUserCode like '%," + this.httpCookie_0.Value + ",%' or BrowUserCode like '%,所有人员,%'   or BrowDeptID like '%," + this.httpCookie_4.Value + ",%' or BrowDeptName like '%,所有部门,%' ) order by SortInfo,ID";
            //SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            //SqlCommand command = new SqlCommand(cmdText, connection);
            //connection.Open();
            //SqlDataReader reader = command.ExecuteReader();
            //while (reader.Read())
            //{
            //    this.method_0(reader["SubjectName"].ToString(), child, reader["ID"].ToString(), reader["UPID"].ToString());
            //}
            //reader.Close();
            //connection.Close();
            //connection.Dispose();
        }

        private void method_0(string string_0, string string_1, string string_2)
        {
            if (string_0 == "所有科目信息")
            {
                this.lblTreeType.Text += "<ul id=\"red\" class=\"treeview-red\">";
            }
            else
            {
                this.lblTreeType.Text += "<ul>";
            }
            string cmdText = "";
            cmdText = "select * from SubjectInfo where UPID='" + string_1 + "' and (BrowUserCode like '%," + this.httpCookie_0.Value + ",%' or BrowUserCode like '%,所有人员,%'   or BrowDeptID like '%," + this.httpCookie_4.Value + ",%' or BrowDeptName like '%,所有部门,%' ) order by SortInfo,ID";
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlCommand command = new SqlCommand(cmdText, connection);
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                var name = reader["SubjectName"].ToString();
                var id = reader["ID"].ToString();
                var upid = reader["UPID"].ToString();
                this.lblTreeType.Text += $"<li><span><a style=\"cursor:pointer\" href=\"TaskInfoList.aspx?SubjectID={id}\"  target=\"mainBookFrame\">{name}</a></span>";
                this.method_0(name, id, upid);
                this.lblTreeType.Text += "</li>";
            }
            reader.Close();
            connection.Close();
            connection.Dispose();

            this.lblTreeType.Text += "</ul>";
            this.lblTreeType.Text = this.lblTreeType.Text.Replace("<ul></ul>", "");
            this.lblTreeType.Text = this.lblTreeType.Text.Replace("<ul id=\"red\" class=\"treeview-red\"></ul>", "");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_3 = new HttpCookie("ExamUserLevel");
            this.httpCookie_3 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_4 = new HttpCookie("ExamDeptID");
            this.httpCookie_4 = base.Request.Cookies["ExamDeptID"];
            this.httpCookie_2 = new HttpCookie("ExamDeptName");
            this.httpCookie_2 = base.Request.Cookies["ExamDeptName"];
            if ((this.httpCookie_0 != null) && !(this.httpCookie_0.Value == ""))
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.httpCookie_4.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_4.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                if (!base.IsPostBack)
                {
                    //this.TreeSubject.Nodes.Clear();
                    //TreeNode node = new TreeNode();
                    //this.method_0("所有科目信息", node, "0", "0");
                    this.lblTreeType.Text = string.Empty;
                    this.method_0("所有科目信息", "0", "0");
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

